package com.hz.edu.controller;

import com.hz.api.model.request.ApiResponse;
import com.hz.edu.service.CourseService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/course-manager")
public class CourseManagerController {

    @Resource
    CourseService courseService;

    @PostMapping("/add-course")
    public String addCourse(@RequestParam("courseName") String courseName, @RequestParam("courseCode") String courseCode,
                            @RequestParam("teacherId") Integer teacherId, @RequestParam("sectionCount") Integer sectionCount,
                            @RequestParam("courseTime") String courseTime, @RequestParam("maxStudentCount") Integer maxStudentCount,
                            @RequestParam("courseProfile") String courseProfile, @RequestParam("textbook") String textbook,
                            @RequestParam("creditsCount") Integer creditsCount, @RequestParam("allScore") Integer allScore,
                            @RequestParam("passScore") Integer passScore) {
        int add = courseService.addCourse(courseName, courseCode, teacherId, sectionCount, courseTime, maxStudentCount, courseProfile,
                textbook, creditsCount, allScore, passScore);
        return add > 0 ? ApiResponse.ok(add) : ApiResponse.intError();
    }
}
